home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / dependantscan / source / requestererror.c < prev    next >
C/C++ Source or Header  |  1995-11-14  |  8KB  |  144 lines

  1. #define DEF_REQUESTERERROR_C
  2.  
  3. #include <exec/types.h>
  4. #include <clib/exec_protos.h>
  5. #include <clib/intuition_protos.h>
  6.  
  7. #include <stdio.h>
  8. #include <stdarg.h>
  9. #include "RequesterError.h"
  10.  
  11. static struct Window *ErrorRequesterWindow = NULL;                    /* default screen for error requesters to show up on */
  12. static char *ErrorRequesterTitle = NULL;                       /* how we will title error requesters */
  13. static char *(*ErrorLocaleFunction)(int message_index) = NULL; /* function to call to get an error message for this applicaiton */
  14. static char *ErrorGadgetText = NULL;                                    /* description of the gadget(s) on the error requesters */
  15.  
  16. /*
  17.     void requester_error_set_defaults(
  18.         struct Window *window,                                                the screen to display error requesters on
  19.         char *title,                                                            the title of error requesters
  20.         char *(*locale_function)(int message_index),                    a function to call to be get error messages
  21.         char *gadget_text)                                                    the text to be used for the gadget(s) on the requesters
  22.  
  23.    * Description
  24.        This function optionally sets up the title of error requesters and/or the array of strings to be used for error messages. If any
  25.        argument is NULL, that item will not be changed.
  26. */
  27. void requester_error_set_defaults(
  28.     struct Window *window,                                                    /* the screen to display error requesters on */
  29.     char *title,                                                                /* the title of error requesters */
  30.     char *(*locale_function)(int message_index),                        /* a function to call to be get error messages */
  31.     char *gadget_text)                                                        /* the text to be used for the gadget(s) on the requesters */
  32. {
  33.     if (window)                                                                    /* if we should set a default screen for our error requesters */
  34.         ErrorRequesterWindow = window;                                    /* put error requests on the same screen as this window */
  35.  
  36.     if (title)                                                                    /* if we should change the name for the error requesters */
  37.         ErrorRequesterTitle = title;                                        /* use this for the name of the error requesters */
  38.  
  39.    if (locale_function)                                        /* if a function to get error messages was supplied  */
  40.        ErrorLocaleFunction = locale_function;                            /* use this function to get messages */
  41.  
  42.    if (gadget_text)                                                            /* if we should change the default gadget text */
  43.        ErrorGadgetText = gadget_text;                                    /* use this for the default gadget text */
  44. }
  45.  
  46. /*
  47.     int vrequester_error(
  48.         struct Window *window,                                                if non-NULL, show the requester window on the same screen as this window
  49.         char *title,                                                            if non-NULL, use this for the title
  50.         char *error_text,                                                        if non-NULL, use this for the error text
  51.        char *gadget_text,                                                    if non-NULL, use this for to define the available gadget(s)
  52.         int error_number,                                                        if 'error_text' is NULL, use ErrorLocaleFunction(error_number)
  53.         va_arg arg_ptr)                                          printf() style arguments for the error text and gadget text
  54.  
  55.    * Description
  56.         This function will display the specified error in a requester optionally entitled 'title' and wait for the user to choose something.
  57.  
  58.         NOTE: Turn off all "Verify Messages" before using this routine. Use ModifyIDCMP() to turn off all messages such as MENUVERIFY before
  59.         calling this function. Neglecting to do so can cause situations where Intuition is waiting for the return of a message that the
  60.         application cannot receive because it's input is shut off while the requester created by this function is up.
  61.  
  62.    This function requires that the intuition.library be open.
  63.  
  64.    * Return Value
  65.       0 = the rightmost gadget was selected
  66.       > 1 = a leftmost gadget was selected (the number of the gadget is returned)
  67. */
  68. int vrequester_error(
  69.     struct Window *window,                                                    /* if non-NULL, show the requester window on the same screen as this window */
  70.     char *title,                                                                /* if non-NULL, use this for the title */
  71.     char *error_text,                                                            /* if non-NULL, use this for the error text */
  72.    char *gadget_text,                                                        /* if non-NULL, use this for to define the available gadget(s) */
  73.     int error_number,                                                            /* if 'error_text' is NULL, use ErrorLocaleFunction(error_number) */
  74.     va_list arg_ptr)                                            /* printf() style arguments for the error text and gadget text */
  75. {
  76.     struct EasyStruct *easy_struct = AllocVec(sizeof(*easy_struct),0);                           /* the structure used to handle the requester */
  77.     int retval = 0;                                                            /* default to the cancel gadget */
  78.  
  79.     if (easy_struct)                                                            /* if we could get enough memory */
  80.     {
  81.         easy_struct->es_StructSize = sizeof(*easy_struct);       /* let intuition know which structure we are using */
  82.         easy_struct->es_Flags = 0;                               /* not yet used */
  83.         easy_struct->es_Title = title ? title : ErrorRequesterTitle;                                        /* use appropriate title */
  84.         easy_struct->es_TextFormat = error_text ? error_text : ErrorLocaleFunction(error_number); /* fetch specified error text */
  85.         easy_struct->es_GadgetFormat = gadget_text ? gadget_text : ErrorGadgetText;                    /* use the appropriate gadget text */
  86.  
  87.       retval = EasyRequestArgs(window ? window : ErrorRequesterWindow, easy_struct, NULL, arg_ptr);
  88.  
  89.       FreeVec(easy_struct);                                                /* don't need this memory anymore */
  90.     }
  91.  
  92.     return (retval);                                                            /* 0 = righmost (cancel), other = gadget number */
  93. }
  94.  
  95. /*
  96.      int requester_error(
  97.         struct Window *window,                                                if non-NULL, show the requester on the same screen as this window
  98.         char *title,                                                            if non-NULL, use this for the title
  99.         char *error_text,                                                        if non-NULL, use this for the error text
  100.        char *gadget_text,                                                    if non-NULL, use this for to define the available gadget(s)
  101.         int error_number,                                                        if 'error_text' is NULL, access ErrorLocaleFunction(error_number)
  102.         ...)                                                                        printf() style arguments for the error text and gadget text
  103.  
  104.     * Description
  105.         This funciton acts exactly like vrequester_error() except that it takes it's arguments individually.
  106.  
  107.    * Return Value
  108.        see vrequester_error()
  109. */
  110. int requester_error(
  111.     struct Window *window,                                                    /* if non-NULL, show the requester on the same screen as this window */
  112.     char *title,                                                                /* if non-NULL, use this for the title */
  113.     char *error_text,                                                            /* if non-NULL, use this for the error text */
  114.    char *gadget_text,                                                        /* if non-NULL, use this for to define the available gadget(s) */
  115.     int error_number,                                                            /* if 'error_text' is NULL, access ErrorLocaleFunction(error_number) */
  116.     ...)                                                                            /* printf() style arguments for the error text and gadget text */
  117. {
  118.     va_list arg_ptr;                                                            /* for dealing with variable arguments */
  119.  
  120.     va_start(arg_ptr,error_number);                                        /* setup the variable argument stuff */
  121.  
  122.     return (vrequester_error(window,title,error_text,gadget_text,error_number,arg_ptr));         /* call the va_arg version of this function */
  123. }
  124.  
  125. /*
  126.     int quick_requester_error(
  127.         int error_number,                                                        index into the errory text array
  128.         ...)                                                                        printf() style arguments for the error text and gadget text
  129.  
  130.     * Description
  131.         This function works exactly like requester_error() except that the values previously setup by a call to requester_error_set_defaults()
  132.         will be used instead of having to pass them on the stack.
  133. */
  134. int quick_requester_error(
  135.     int error_number,                                                            /* index into the errory text array */
  136.     ...)                                                                            /* printf() style arguments for the error text and gadget text */
  137. {
  138.     va_list arg_ptr;                                                            /* for dealing with variable arguments */
  139.  
  140.     va_start(arg_ptr,error_number);                                        /* setup the variable argument stuff */
  141.  
  142.     return (vrequester_error(NULL,NULL,NULL,NULL,error_number,arg_ptr));                         /* call the va_arg version of this function */
  143. }
  144.